#include <iostream>
#include <string>

#include "mqtt_publisher.h"

int main(int argc, char* argv[]) {
  std::string topic = "sensors/temperature";
  int count = 10;
  int interval = 2;

  // 简单的命令行参数处理
  if (argc > 1) {
    topic = argv[1];
  }
  if (argc > 2) {
    count = std::stoi(argv[2]);
  }
  if (argc > 3) {
    interval = std::stoi(argv[3]);
  }

  std::cout << "=== MQTT 发布者演示 ===" << std::endl;
  std::cout << "发布主题: " << topic << std::endl;
  std::cout << "消息数量: " << count << std::endl;
  std::cout << "发布间隔: " << interval << "秒" << std::endl;
  std::cout << "Broker: tcp://192.168.202.1:1883" << std::endl;
  std::cout << "======================" << std::endl;

  // 创建发布者
  MQTTPublisher publisher("tcp://192.168.202.1:1883", "demo_publisher");

  // 连接
  if (!publisher.Connect()) {
    std::cerr << "连接失败!" << std::endl;
    return 1;
  }

  // 发布温度数据
  publisher.PublishTemperature(topic, interval, count);

  // 断开连接
  publisher.DisConnect();

  std::cout << "发布者程序结束" << std::endl;
  return 0;
}